﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Controls;
using System.Windows;
using System.Runtime.ConstrainedExecution;

namespace ABELGX
{
    public class SwitchVM
    {
        public RegisterBool RegisterCmd { get; }
        public RegisterBool RegisterInfo { get; }
        public SwitchVM(UserControlSwitch button, RegisterBool regCmd,RegisterBool regInfo)
        {
            RegisterCmd = regCmd;
            RegisterInfo = regInfo;
            button.Visibility = regInfo.Visiable ? Visibility.Visible : Visibility.Hidden;
            if(!regInfo.Visiable)
            {
                return;
            }
            if (!string.IsNullOrWhiteSpace(regInfo.Set.Name))
            {
                button.Title = regInfo.Set.Name;
            }
            button.DataContext = regInfo;
            button.AddHandler(Button.MouseUpEvent, new RoutedEventHandler(Button_Up), true);
            button.AddHandler(Button.TouchUpEvent, new RoutedEventHandler(Button_Up), true);
        }

        public void Button_Up(object sender, RoutedEventArgs e)
        {
            if (RegisterCmd == null)
            {
                return;
            }
            RegisterCmd.Value = !RegisterInfo.Value;
        }
    }
}
